import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'
import Layout from '@/components/layout/Layout.vue'
import { getModuleByUser } from '@/api/https'
Vue.use(VueRouter)

const routes = [{
  path: '/login',
  name:'login',
  component: () => import('@/views/Login'),
  meta: {
    title: '登录',
    showLayout: false,
    keepAlive: false,
    showMenu:false
  }
},{
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: '坝群总览',
      icon:'&#xe63b;',
      keepAlive: false,
      showLayout: false,
      moduleId:1,
    },
    children:[]
  },
  {
    path: '/index',
    name: 'index',
    component: Layout,
    meta: {
      title: '首页',
      icon: '&#xe7eb;',
      moduleId:3
    },
    children: [
      {
        path: 'basin',
        name: 'basin',
        component: ()=>import('@/views/index/basin.vue'),
        meta: {
          title: '流域电站',
          icon: '&#xe62c;',
          keepAlive: true,
          moduleId:2
        }
      },
      {
        path: 'station',
        name: 'station',
        component: ()=>import('@/views/index/station.vue'),
        meta: {
          title: '电站首页',
          icon: '&#xe6b5;',
          keepAlive: true 
        }
      }
    ]
  },
  {
    path: '/information',
    name: 'information',
    component: Layout, 
    meta: {
      title: '信息管理',
      icon: '&#xe605;',
      moduleId:4
    },
    children: [
      {
        path: 'monitor',
        name: 'monitor',
        component: ()=>import('@/views/information/monitor.vue'),
        meta: {
          title: '监测数据',
          icon: '&#xe6a0;',
          keepAlive: true ,
          moduleId:5
        }
      },
      {
        path: 'visitation',
        name: 'visitation',
        component: ()=>import('@/views/information/visitation.vue'),
        meta: {
          title: '巡视数据',
          icon: '&#xe666;',
          keepAlive: true,
          moduleId:6 
        }
      },
      {
        path: 'instrument',
        name: 'instrument',
        component: ()=>import('@/views/information/instrument.vue'),
        meta: {
          title: '仪器信息',
          icon: '&#xe627;',
          keepAlive: true,
          moduleId:7 
        }
      },
      {
        path: 'log',
        name: 'log',
        component: ()=>import('@/views/information/log.vue'),
        meta: {
          title: '日志查询',
          icon: '&#xe7c3;',
          keepAlive: true,
          moduleId:8 
        }
      },
      {
        path: 'engineering',
        name: 'engineering',
        component: ()=>import('@/views/information/engineering.vue'),
        meta: {
          title: '工程资料',
          icon: '&#xe607;',
          keepAlive: true,
          moduleId:9 
        }
      },
      {
        path: 'ledger',
        name: 'ledger',
        component: ()=>import('@/views/information/ledger.vue'),
        meta: {
          title: '台帐管理',
          icon: '&#xe671;',
          keepAlive: true ,
          moduleId:41
        }
      }
    ]
  },
  {
    path: '/analysis',
    name: 'analysis',
    component: Layout, 
    meta: {
      title: '信息分析',
      icon: '&#xe623;',
      moduleId:10
    },
    children: [
      {
        path: 'effectiveness',
        name: 'effectiveness',
        component: ()=>import('@/views/analysis/effectiveness.vue'),
        meta: {
          title: '数据有效性统计',
          icon: '&#xe656;',
          keepAlive: true,
          moduleId:11 
        }
      },
      {
        path: 'tableCompilation',
        name: 'tableCompilation',
        component: ()=>import('@/views/analysis/tableCompilation.vue'),
        meta: {
          title: '表格整编',
          icon: '&#xe615;',
          keepAlive: true,
          moduleId:12 
        }
      },
      {
        path: 'chartLine',
        name: 'chartLine',
        component: ()=>import('@/views/analysis/chartLine.vue'),
        meta: {
          title: '图形整编',
          icon: '&#xe7f7;',
          keepAlive: true,
          moduleId:13 
        }
      },
      {
        path: 'report',
        name: 'report',
       component: ()=>import('@/views/analysis/report.vue'),
        meta: {
          title: '报告整编',
          icon: '&#xe811;',
          keepAlive: true,
          moduleId:14 
        }
      }
    ]
  },
  {
    path: '/Monitoring',
    name: 'Monitoring',
    component: Layout, 
    meta: {
      title: '监控评价',
      icon: '&#xe64e;',
      moduleId:15
    },
    children: [
      {
        path: 'onLine',
        name: 'onLine',
        component: ()=>import('@/views/Monitoring/onLine.vue'),
        meta: {
          title: '实时评价',
          icon: '&#xe640;',
          keepAlive: true,
          moduleId:16 
        }
      },
      {
        path: 'comprehensive',
        name: 'comprehensive',
        component: ()=>import('@/views/Monitoring/comprehensive.vue'),
        meta: {
          title: '综合评价',
          icon: '&#xe678;',
          keepAlive: true,
          moduleId:17 
        }
      },
      {
        path: 'consultation',
        name: 'consultation',
        component: ()=>import('@/views/Monitoring/consultation.vue'),
        meta: {
          title: '远程会商系统',
          icon: '&#xe67c;',
          keepAlive: true,
          moduleId:42
        }
      }
    ]
  },
  {
    path: '/setting',
    name: 'setting',
    component: Layout, 
    meta: {
      title: '系统设置',
      icon: '&#xe601;',
      moduleId:18
    },
    children: [
      {
        path: 'stationManagement',
        name: 'stationManagement',
        component: ()=>import('@/views/setting/stationManagement.vue'),
        meta: {
          title: '流域电站管理',
          icon: '&#xe61d;',
          keepAlive: true,
          moduleId:19 
        }
      },
      {
        path: 'permission',
        name: 'permission',
        component: ()=>import('@/views/setting/permission.vue'),
        meta: {
          title: '权限管理',
          icon: '&#xe642;',
          keepAlive: true,
          moduleId:20 
        }
      },
      {
        path: 'manufacturer',
        name: 'manufacturer',
        component: ()=>import('@/views/setting/manufacturer.vue'),
        meta: {
          title: '厂家仪器产品入库',
          icon: '&#xe619;',
          keepAlive: true,
          moduleId:21 
        }
      },
      {
        path: 'monitorData',
        name: 'monitorData',
        component: ()=>import('@/views/setting/monitorData.vue'),
        meta: {
          title: '监测数据仪器管理',
          icon: '&#xe627;',
          keepAlive: true,
          moduleId:22 
        }
      },
      {
        path: 'earlyWarning',
        name: 'earlyWarning',
        component: ()=>import('@/views/setting/earlyWarning.vue'),
        meta: {
          title: '预警响应管理',
          icon: '&#xe653;',
          keepAlive: true ,
          moduleId:23
        }
      },
      {
        path: 'imageSetting',
        name: 'imageSetting',
        component: ()=>import('@/views/setting/imageSetting.vue'),
        meta: {
          title: '图片数字化',
          icon: '&#xe8ba;',
          keepAlive: true,
          moduleId:24 
        }
      },
      {
        path: 'tableSetting',
        name: 'tableSetting',
        component: ()=>import('@/views/setting/tableSetting.vue'),
        meta: {
          title: '表格模板',
          icon: '&#xe615;',
          keepAlive: true,
          moduleId:29 
        }
      },
      {
        path: 'chartLineSetting',
        name: 'chartLineSetting',
        component: ()=>import('@/views/setting/chartLineSetting.vue'),
        meta: {
          title: '过程线模板',
          icon: '&#xe661;',
          keepAlive: true,
          moduleId:30 
        }
      },
      {
        path: 'reportSetting',
        name: 'reportSetting',
        component: ()=>import('@/views/setting/reportSetting.vue'),
        meta: {
          title: '报告模板',
          icon: '&#xe811;',
          keepAlive: true,
          moduleId:31 
        }
      },
      {
        path: 'visitationSetting',
        name: 'visitationSetting',
        component: ()=>import('@/views/setting/visitationSetting.vue'),
        meta: {
          title: '巡视模板',
          icon: '&#xe666;',
          keepAlive: true,
          moduleId:33 
        }
      },
      {
        path: 'videoSetting',
        name: 'videoSetting',
        component: ()=>import('@/views/setting/videoSetting.vue'),
        meta: {
          title: '视频设置',
          icon: '&#xe851;',
          keepAlive: true,
          moduleId:34 
        }
      },
      {
        path: 'IndicatorType',
        name: 'IndicatorType',
        component: ()=>import('@/views/setting/IndicatorType.vue'),
        meta: {
          title: '指标类型管理',
          icon: '&#xe606;',
          keepAlive: true ,
          moduleId:25
        }
      },
      {
        path: 'IndexCalculation',
        name: 'IndexCalculation',
        component: ()=>import('@/views/setting/IndexCalculation.vue'),
        meta: {
          title: '指标计算配置',
          icon: '&#xe68f;',
          keepAlive: true,
          moduleId:26 
        }
      }
    ]
  },
  {
    path: '/collect',
    name: 'collect',
    component: Layout, 
    meta: {
      title: '采集管理',
      icon: '&#xe835;',
      moduleId: 35
    },
    children: [
      {
        path: 'CollectionOverview',
        name: 'CollectionOverview',
        component: ()=>import('@/views/collect/CollectionOverview.vue'),
        meta: {
          title: '采集总览',
          icon: '&#xe644;',
          keepAlive: true ,
          moduleId:36
        }
      },
      {
        path: 'database',
        name: 'database',
        component: ()=>import('@/views/collect/database.vue'),
        meta: {
          title: '数据库映射',
          icon: '&#xe626;',
          keepAlive: true ,
          moduleId:37
        }
      },
      {
        path: 'measurementPoint',
        name: 'measurementPoint',
        component: ()=>import('@/views/collect/measurementPoint.vue'),
        meta: {
          title: '测点映射',
          icon: '&#xe7cf;',
          keepAlive: true,
          moduleId:38 
        }
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to, from, next) => {
  // 检查路由是否存在
  if (to.matched.length === 0) {
    // 路由不存在，跳转到登录页
    next('/login')
  } else if (to.path !== '/login' && !sessionStorage.getItem('token')) {
    // 如果需要认证且未登录，跳转到登录页
    next('/login')
  } else {
    // 其他情况正常放行
    next()
  }
})

export default router